package cc.wanforme.chipmunity.testController;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.controller.base.BaseController;
import cc.wanforme.chipmunity.system.po.user.User;
import cc.wanforme.chipmunity.system.service.interfaces.UserService;

/**
 * @author wanne
 * 2019年7月24日
 * 
 */
@Controller
public class RegisterTestController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(RegisterTestController.class);
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/register-te")
	@ResponseBody
	public User register(@RequestBody User user ) {
		try {
			userService.saveUser(user, user.getPassword());
		} catch (Exception e) {
			log.error("注册失败："+user);
			log.error(e.getMessage());
			return user;
		}
		return user;
	}
	
	/** 测试权限的地方
	 * @param user
	 * @return
	 */
	@RequestMapping("/re")
	@ResponseBody
	//@PreAuthorize("hasAuthority('testAu')")
	@PreAuthorize("hasAuthority('passage:reply')")
	public User re(@RequestBody User user)  {
		/** 该方法需要USER权限*/
		System.out.println("receive: "+user);
		return user;
	}
	
}
